package com.schoolcloud.social.controller.forum;

import com.schoolcloud.common.model.PageDTO;
import com.schoolcloud.common.model.R;
import com.schoolcloud.social.entity.SocPost;
import com.schoolcloud.social.query.UserForumQuery;
import com.schoolcloud.social.query.PostRepliesQuery;
import com.schoolcloud.social.service.PostInteractionService;
import com.schoolcloud.social.service.SocPostService;
import com.schoolcloud.social.dto.SocPostCreateDTO;
import com.schoolcloud.social.query.PostQuery;
import com.schoolcloud.social.vo.ForumUserVO;
import com.schoolcloud.social.vo.SocPostInfoVO;
import com.schoolcloud.social.vo.SocPostItemVO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


@RequiredArgsConstructor
@RestController
@RequestMapping("social/posts")
public class SocPostController {
    private final SocPostService socPostService;
    private final PostInteractionService postInteractionService;

    @PostMapping
    public R<?> addPost(@RequestBody SocPostCreateDTO socPost) {
        postInteractionService.addPost(socPost);
        return R.ok();
    }

    @DeleteMapping("{postId}")
    public R<Object> delPost(@PathVariable String postId) {
        socPostService.removeById(postId);
        return R.ok();
    }

    @GetMapping("{postId}")
    public R<Object> getPostById(@PathVariable String postId) {
        SocPost socPost = socPostService.getById(postId);
        return R.ok(socPost);
    }

    @PutMapping
    public R<Object> modifyPost(@RequestBody SocPost socPost) {
        socPostService.modifyPost(socPost);
        return R.ok();
    }

    @GetMapping("/page")
    public R<PageDTO<SocPostItemVO>> GetPostList(PostQuery searchDTO) {
        PageDTO<SocPostItemVO> page = postInteractionService.getPostItemVOPage(searchDTO);
        return R.ok(page);
    }

    @GetMapping("/info")
    public R<SocPostInfoVO> getPostInfo(PostRepliesQuery query) {
        SocPostInfoVO socPostInfoVO = postInteractionService.getPostInfo(query);
        return R.ok(socPostInfoVO);
    }
    @GetMapping("/user/{userId}")
    public R<ForumUserVO> getPostUserInfo(@PathVariable String userId) {
        ForumUserVO postUserVO = postInteractionService.getUserInfo(userId);
        return R.ok(postUserVO);
    }

}
